package com.ruoyi.multab.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.multab.domain.MulModelMain;
import com.ruoyi.multab.service.IMulModelMainService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 仿真模型Controller
 * 
 * @author zhouwc
 * @date 2020-08-08
 */
@Controller
@RequestMapping("/multab/multabmain")
public class MulModelMainController extends BaseController
{
    private String prefix = "multab/multabmain";

    @Autowired
    private IMulModelMainService mulModelMainService;

    @RequiresPermissions("multab:multabmain:view")
    @GetMapping()
    public String multabmain()
    {
        return prefix + "/multabmain";
    }
    @RequiresPermissions("multab:multabmain:view")
    @GetMapping("/echart")
    public String modelEcharts()
    {
        return prefix + "/echart";
    }

    /**
     * 查询仿真模型列表
     */
    @RequiresPermissions("multab:multabmain:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MulModelMain mulModelMain)
    {
        startPage();
        List<MulModelMain> list = mulModelMainService.selectMulModelMainList(mulModelMain);
        return getDataTable(list);
    }

    /**
     * 导出仿真模型列表
     */
    @RequiresPermissions("multab:multabmain:export")
    @Log(title = "仿真模型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MulModelMain mulModelMain)
    {
        List<MulModelMain> list = mulModelMainService.selectMulModelMainList(mulModelMain);
        ExcelUtil<MulModelMain> util = new ExcelUtil<MulModelMain>(MulModelMain.class);
        return util.exportExcel(list, "multabmain");
    }

    /**
     * 新增仿真模型
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存仿真模型
     */
    @RequiresPermissions("multab:multabmain:add")
    @Log(title = "仿真模型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MulModelMain mulModelMain)
    {
        return toAjax(mulModelMainService.insertMulModelMain(mulModelMain));
    }

    /**
     * 修改仿真模型
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        MulModelMain mulModelMain = mulModelMainService.selectMulModelMainById(id);
        mmap.put("mulModelMain", mulModelMain);
        return prefix + "/edit";
    }

    /**
     * 修改保存仿真模型
     */
    @RequiresPermissions("multab:multabmain:edit")
    @Log(title = "仿真模型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MulModelMain mulModelMain)
    {
        return toAjax(mulModelMainService.updateMulModelMain(mulModelMain));
    }

    /**
     * 删除仿真模型
     */
    @RequiresPermissions("multab:multabmain:remove")
    @Log(title = "仿真模型", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mulModelMainService.deleteMulModelMainById(Integer.parseInt(ids)));
    }
}
